/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Commands.ipp.zapt

#include <clusters/NetworkCommissioning/Commands.h>

#include <app/data-model/Decode.h>
#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip {
namespace app {
namespace Clusters {
namespace NetworkCommissioning {
namespace Commands {
namespace ScanNetworks {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kSsid), ssid);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kSsid))
        {
            err = DataModel::Decode(reader, ssid);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace ScanNetworks.
namespace ScanNetworksResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus);
    encoder.Encode(to_underlying(Fields::kDebugText), debugText);
    encoder.Encode(to_underlying(Fields::kWiFiScanResults), wiFiScanResults);
    encoder.Encode(to_underlying(Fields::kThreadScanResults), threadScanResults);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkingStatus))
        {
            err = DataModel::Decode(reader, networkingStatus);
        }
        else if (__context_tag == to_underlying(Fields::kDebugText))
        {
            err = DataModel::Decode(reader, debugText);
        }
        else if (__context_tag == to_underlying(Fields::kWiFiScanResults))
        {
            err = DataModel::Decode(reader, wiFiScanResults);
        }
        else if (__context_tag == to_underlying(Fields::kThreadScanResults))
        {
            err = DataModel::Decode(reader, threadScanResults);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace ScanNetworksResponse.
namespace AddOrUpdateWiFiNetwork {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kSsid), ssid);
    encoder.Encode(to_underlying(Fields::kCredentials), credentials);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    encoder.Encode(to_underlying(Fields::kNetworkIdentity), networkIdentity);
    encoder.Encode(to_underlying(Fields::kClientIdentifier), clientIdentifier);
    encoder.Encode(to_underlying(Fields::kPossessionNonce), possessionNonce);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kSsid))
        {
            err = DataModel::Decode(reader, ssid);
        }
        else if (__context_tag == to_underlying(Fields::kCredentials))
        {
            err = DataModel::Decode(reader, credentials);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }
        else if (__context_tag == to_underlying(Fields::kNetworkIdentity))
        {
            err = DataModel::Decode(reader, networkIdentity);
        }
        else if (__context_tag == to_underlying(Fields::kClientIdentifier))
        {
            err = DataModel::Decode(reader, clientIdentifier);
        }
        else if (__context_tag == to_underlying(Fields::kPossessionNonce))
        {
            err = DataModel::Decode(reader, possessionNonce);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AddOrUpdateWiFiNetwork.
namespace AddOrUpdateThreadNetwork {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kOperationalDataset), operationalDataset);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kOperationalDataset))
        {
            err = DataModel::Decode(reader, operationalDataset);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace AddOrUpdateThreadNetwork.
namespace RemoveNetwork {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkID), networkID);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkID))
        {
            err = DataModel::Decode(reader, networkID);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace RemoveNetwork.
namespace NetworkConfigResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus);
    encoder.Encode(to_underlying(Fields::kDebugText), debugText);
    encoder.Encode(to_underlying(Fields::kNetworkIndex), networkIndex);
    encoder.Encode(to_underlying(Fields::kClientIdentity), clientIdentity);
    encoder.Encode(to_underlying(Fields::kPossessionSignature), possessionSignature);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkingStatus))
        {
            err = DataModel::Decode(reader, networkingStatus);
        }
        else if (__context_tag == to_underlying(Fields::kDebugText))
        {
            err = DataModel::Decode(reader, debugText);
        }
        else if (__context_tag == to_underlying(Fields::kNetworkIndex))
        {
            err = DataModel::Decode(reader, networkIndex);
        }
        else if (__context_tag == to_underlying(Fields::kClientIdentity))
        {
            err = DataModel::Decode(reader, clientIdentity);
        }
        else if (__context_tag == to_underlying(Fields::kPossessionSignature))
        {
            err = DataModel::Decode(reader, possessionSignature);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace NetworkConfigResponse.
namespace ConnectNetwork {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkID), networkID);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkID))
        {
            err = DataModel::Decode(reader, networkID);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace ConnectNetwork.
namespace ConnectNetworkResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkingStatus), networkingStatus);
    encoder.Encode(to_underlying(Fields::kDebugText), debugText);
    encoder.Encode(to_underlying(Fields::kErrorValue), errorValue);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkingStatus))
        {
            err = DataModel::Decode(reader, networkingStatus);
        }
        else if (__context_tag == to_underlying(Fields::kDebugText))
        {
            err = DataModel::Decode(reader, debugText);
        }
        else if (__context_tag == to_underlying(Fields::kErrorValue))
        {
            err = DataModel::Decode(reader, errorValue);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace ConnectNetworkResponse.
namespace ReorderNetwork {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kNetworkID), networkID);
    encoder.Encode(to_underlying(Fields::kNetworkIndex), networkIndex);
    encoder.Encode(to_underlying(Fields::kBreadcrumb), breadcrumb);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kNetworkID))
        {
            err = DataModel::Decode(reader, networkID);
        }
        else if (__context_tag == to_underlying(Fields::kNetworkIndex))
        {
            err = DataModel::Decode(reader, networkIndex);
        }
        else if (__context_tag == to_underlying(Fields::kBreadcrumb))
        {
            err = DataModel::Decode(reader, breadcrumb);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace ReorderNetwork.
namespace QueryIdentity {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kKeyIdentifier), keyIdentifier);
    encoder.Encode(to_underlying(Fields::kPossessionNonce), possessionNonce);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kKeyIdentifier))
        {
            err = DataModel::Decode(reader, keyIdentifier);
        }
        else if (__context_tag == to_underlying(Fields::kPossessionNonce))
        {
            err = DataModel::Decode(reader, possessionNonce);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace QueryIdentity.
namespace QueryIdentityResponse {

CHIP_ERROR Type::Encode(DataModel::FabricAwareTLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kIdentity), identity);
    encoder.Encode(to_underlying(Fields::kPossessionSignature), possessionSignature);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kIdentity))
        {
            err = DataModel::Decode(reader, identity);
        }
        else if (__context_tag == to_underlying(Fields::kPossessionSignature))
        {
            err = DataModel::Decode(reader, possessionSignature);
        }

        ReturnErrorOnFailure(err);
    }
}
} // namespace QueryIdentityResponse.
} // namespace Commands
} // namespace NetworkCommissioning
} // namespace Clusters
} // namespace app
} // namespace chip
